package fun.anin.aninhongbao.receive.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;

/***
 *
 * @author anin
 * @date: 2020/3/31 18:46
 * @version : V1.0
 */
@Configuration
public class RedPacketMQConfig {

    /**
     * 红包记录队列
     */
    @Bean
    public Queue recordQueue(){
        return new Queue("redpacket.record");
    }
    /**
     * 退还红包延迟队列
     */
    @Bean
    public Queue backQueue(){
        return new Queue("redpacket.back");
    }
    /**
     * 标记为幸运王
     */
    @Bean
    public Queue markAsLuckQueue(){
        return new Queue("redpacket.markAsLuck");
    }

    @Bean
    public TopicExchange recordExchange() {
        return new TopicExchange("redpacket.RecordExchange");
    }

    @Bean
    public CustomExchange backExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange("redpacket.BackExchange", "x-delayed-message",true, false,args);
    }

    @Bean
    public Binding bindingRecordExchange() {
        return BindingBuilder.bind(recordQueue()).to(recordExchange()).with("redpacket.record");
    }

    @Bean
    public Binding bindingBackExchange() {
        return BindingBuilder.bind(backQueue()).to(backExchange()).with("redpacket.back").noargs();
    }
}
